package com.by.controller.sys;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.by.common.bean.PageBean;
import com.by.common.bean.ResultBean;
import com.by.controller.BaseController;
import com.by.entity.sys.Dict;
import com.by.service.sys.DictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/dict")
public class DictController extends BaseController {

    @Autowired
    DictService dictService;

    @PostMapping("/save")
    public ResultBean save(@RequestBody Dict dict) {
        int rs = dictService.save(dict);
        return rs == 1 ? success("保存成功") : fail("保存失败");
    }


    @PostMapping("/child")
    public ResultBean query(@RequestBody Map map) {
        PageBean bean = dictService.query(map);
        return success("字典数据列表", bean);
    }


    @GetMapping("/type")
    public ResultBean queryDictType() {
        List list = dictService.queryType();
        return success("字典类型", list);
    }

    @GetMapping("/delete")
    public ResultBean deleteType(String id) {
        int flag = dictService.delete(id);
        return flag == 1 ? success("删除成功") : fail("删除失败");
    }

    @PostMapping("/update")
    public ResultBean update(@RequestBody Dict dict) {
        int rs = dictService.update(dict);
        return rs == 1 ? success("修改成功") : fail("修改失败");
    }

    @GetMapping("/queryDictByType")
    public ResultBean queryDictByType(String type) {
        List list = dictService.queryDictByType(type);
        return success("字典数据", list);
    }

    @GetMapping("/queryDictByTypes")
    public ResultBean queryDictByTypes(String types) {
        Map map = dictService.queryDictByTypes(types);
        return success("字典数据", map);
    }
}
